package com.hmall.search.listener;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class ItemListener {

    // 新增商品
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "item.add", durable = "true"),
            exchange = @Exchange(name = "item.direct", type = "direct"),
            key = "add"
    ))
    public void listenAdd(Long itemId) {
        System.out.println("接收到新增商品消息，商品ID：" + itemId);
    }

    // 修改商品
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "item.update", durable = "true"),
            exchange = @Exchange(name = "item.direct", type = "direct"),
            key = "update"
    ))
    public void listenUpdate(Long itemId) {
        System.out.println("接收到修改商品消息，商品ID：" + itemId);

    }
    // 删除商品
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "item.del", durable = "true"),
            exchange = @Exchange(name = "item.direct", type = "direct"),
            key = "del"
    ))
    public void listenDelete(Long itemId) {
        System.out.println("接收到删除商品消息，商品ID：" + itemId);
    }
}
